/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/
/*
Authors: Ram Ovadia 201374022 and Lior Fass 300069705
Project: HW Assignment 4 
Description: This is the header of the library of common functionality in Oiway.  
*/
/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#ifndef COMMON_UTILS_H
#define COMMON_UTILS_H

#include <stdlib.h>
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
#include <string.h>

#define _CRT_SECURE_NO_WARNINGS

#define CLIENT_S		"client"
#define SERVER_S		"server"

#define LOCAL_HOST_S	"localhost"
#define LOCAL_HOST_A	"127.0.0.1"
#define IP_ADDR_MAX		16

#define SIDE_ARG		1

#define ADDRESS_ARG		2
#define C_COORD			3
#define C_LOG_ARG		7

#define S_GRAPH_ARG		3
#define S_MAXC_ARG		4
#define S_LOG_ARG		5

#define GPS_SEMAPHORE_STR "GPS_SEMAPHORE"
#define MAX_LINE_LENGTH 1024
#define GPS_PORT	52000 
#define SERVER_PORT 51000

#pragma comment(lib,"ws2_32.lib") //Winsock Library

/*
 * initiates winsock.   
 * 
 * Input:
 * -----    
 *
 * Output:
 * -----
 *
 */
int winsock_init();

/*
 * Creates a process.    
 * 
 * Input:
 * -----    
 * CommandLine - buffer holding the command, the process will be executing. 
 * ProcessInfoPtr - preallocated struct to hold process information.
 *
 * Output:
 * -----
 * TRUE - successful
 * FALSE - unsuccessful
 * ProcessInfoPtr will point to struct holding up-to-date process information. 
 */
BOOL CreateProcessSimple( LPTSTR CommandLine, PROCESS_INFORMATION *ProcessInfoPtr );

/*
 * Writes buffer to screen and log file.    
 * 
 * Input:
 * -----    
 * buf - pointer to buffer to be written. 
 * file - log file pointer. 
 *
 * Output:
 * -----
 * void
 */
void writeToLog(FILE *file, char *buf);

/*
 * Writes buffer to screen and log file. Supports formatted output.     
 * 
 * Input:
 * -----    
 * Format - format string
 * ... - variables used in format string. 
 * file - log file pointer. 
 *
 * Output:
 * -----
 * void
 */
void writeLogAndScreen(FILE *file,const char * Format,...);

/*
 * tests the input arguments of main.     
 * 
 * Input:
 * -----    
 * argc, argv[] 
 *
 * Output:
 * -----
 * 0 - valid input
 * 1 - invalid input
 */
int main_test_input(int argc, char *argv[]);

/*
 * tests if string represents an integer argument.      
 * 
 * Input:
 * -----    
 * str - pointer to char array to be tested.  
 *
 * Output:
 * -----
 * 0 - str represents an integer.
 * 1 - str does not represent an integer. 
 */
BOOL isInteger(char *str);


#endif //COMMON_UTILS_H